from apps.system.models import Company, Department
from extensions.serializers import *


class GetTokenRequest(Serializer):
    number = CharField(label='Team 编号')
    username = CharField(label='用户名')
    password = CharField(label='密码')

class SMSRequest(Serializer):
    mobile = CharField(label='手机号码')
    sys_name = CharField(label='系统名称')

class SMSGetTokenRequest(Serializer):
    mobile = CharField(label='手机号码')
    code = CharField(label='验证码')
    sys_name = CharField(label='系统名称')


class GetTokenResponse(Serializer):
    refresh = CharField(label='刷新令牌')
    access = CharField(label='访问令牌')


class RefreshTokenRequest(Serializer):
    refresh = CharField(label='刷新令牌')


class RefreshTokenResponse(Serializer):
    access = CharField(label='访问令牌')


class UserInfoResponse(Serializer):
    class CompanyItemSerializer(BaseSerializer):

        class Meta:
            model = Company
            fields = ['id', 'name','coding_abbreviation','index']

    class DepartmentItemSerializer(BaseSerializer):

        class Meta:
            model = Department
            fields = ['id', 'name','index']

    id = IntegerField(label='用户ID')
    username = CharField(label='用户名')
    name = CharField(label='名字')
    phone = CharField(label='手机号码')
    company_item = CompanyItemSerializer(source='company', many=False, read_only=True, label='所属公司')
    department_item = DepartmentItemSerializer(source='department', many=False, read_only=True, label='部门Item')
    is_manager = BooleanField(label='管理员状态')
    permissions = JSONField(label='权限')
    evaluation_authorities = JSONField(label='参评权限')


class SetPasswordRequest(Serializer):
    old_password = CharField(label='旧密码')
    new_password = CharField(label='新密码')


__all__ = [
    'GetTokenRequest', 'GetTokenResponse',
    'RefreshTokenRequest', 'RefreshTokenResponse',
    'UserInfoResponse', 'SetPasswordRequest',
]
